<html>
<head><meta charset="utf-8"><title>Drop with pin? · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html">Drop with pin?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="231307913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/231307913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#231307913">(Mar 22 2021 at 13:19)</a>:</h4>
<p>Will be <code>fn drop(self: Pin&lt;&amp;mut Self&gt;)</code> included in 2021 edition?</p>



<a name="231327547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/231327547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#231327547">(Mar 22 2021 at 15:17)</a>:</h4>
<p><span class="user-mention" data-user-id="328907">@Soveu</span> i'm not aware of any plans for that yet. but there's still time left if there's a concrete proposal</p>



<a name="231335901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/231335901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#231335901">(Mar 22 2021 at 16:00)</a>:</h4>
<p>what is that :)</p>



<a name="231358065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/231358065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#231358065">(Mar 22 2021 at 18:10)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/268952-edition-2021/topic/Drop.20with.20pin.3F/near/231335901">said</a>:</p>
<blockquote>
<p>what is that :)</p>
</blockquote>
<p>basically, current definition of <code>Drop</code> can be kinda unsound when used with <code>!Unpin</code> types, because it gives you <code>&amp;mut Self</code> instead of <code>Pin&lt;&amp;mut Self&gt;</code> so some workarounds are needed, for example</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="w"> </span><span class="nb">Drop</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">PinnedStruct</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">fn</span> <span class="nf">drop</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="cm">/* We have just &amp;mut self even though the pointer should be also pinned */</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">pin_drop</span><span class="p">(</span><span class="n">seif</span>: <span class="nc">Pin</span><span class="o">&lt;&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">Self</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">      </span><span class="cm">/* Using it here is now safer */</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="n">pin_drop</span><span class="p">(</span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">Pin</span>::<span class="n">new_unchecked</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span><span class="p">});</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="231358586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/231358586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#231358586">(Mar 22 2021 at 18:14)</a>:</h4>
<p><span class="user-mention" data-user-id="120054">@Jon Gjengset</span> was talking about this during his <code>Pin</code> Crust of Rust stream</p>



<a name="231360876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/231360876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#231360876">(Mar 22 2021 at 18:29)</a>:</h4>
<p>and it doesn't make drop of <code>Unpin</code> types more complex, just <code>Pin::get_mut</code> is needed</p>



<a name="232174605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/232174605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#232174605">(Mar 28 2021 at 15:47)</a>:</h4>
<p>Yeah, <code>Pin&lt;&amp;mut Self&gt;</code> is the right receiver type for <code>Drop</code></p>



<a name="232174639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/232174639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#232174639">(Mar 28 2021 at 15:47)</a>:</h4>
<p>the fact that it is currently <code>&amp;mut Self</code> means that the <code>Pin</code> docs need to specifically warn about being careful in the destructor</p>



<a name="233085744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233085744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233085744">(Apr 04 2021 at 14:54)</a>:</h4>
<p><a href="https://github.com/rust-lang/rfcs/issues/3105">https://github.com/rust-lang/rfcs/issues/3105</a></p>



<a name="233100158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233100158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233100158">(Apr 04 2021 at 17:37)</a>:</h4>
<p>This is easily going to be the most invasive change in the edition, if we go forward with it.</p>



<a name="233100245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233100245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233100245">(Apr 04 2021 at 17:39)</a>:</h4>
<p>Regarding the "use compiler magic" solution, what if we used a different method, instead? We could call pin_drop instead of drop, on pinned types, so that drop doesn't have to have different parameter types. That would mean most code doesn't need to change.</p>



<a name="233100355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233100355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233100355">(Apr 04 2021 at 17:40)</a>:</h4>
<p>Or, for that matter, we could use compiler magic to provide a default implementation of pin_drop for Unpin that calls drop. Effectively, a "conditional default impls" mechanism for traits.</p>



<a name="233100394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233100394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233100394">(Apr 04 2021 at 17:41)</a>:</h4>
<p>Then, the error message you would get when using a type that is not Unpin would make perfect sense: no impl of pin_drop.</p>



<a name="233102373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233102373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233102373">(Apr 04 2021 at 18:18)</a>:</h4>
<p>By "more problems" i was thinking about case where a type is generic over T</p>



<a name="233102400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233102400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233102400">(Apr 04 2021 at 18:19)</a>:</h4>
<p>then, how to handle both pinned and Unpinned cases?</p>



<a name="233103047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233103047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233103047">(Apr 04 2021 at 18:32)</a>:</h4>
<p>The best middle-ground between the different issues would be, imho, to have a <code>PinnedDrop</code> trait with a blanket impl of <code>Drop</code> for it (<em>à la</em> <a href="https://github.com/taiki-e/pin-project/blob/c8c8b5db302ad7b26d5c59da07bd1fa78d1173d3/src/lib.rs#L185-L188">https://github.com/taiki-e/pin-project/blob/c8c8b5db302ad7b26d5c59da07bd1fa78d1173d3/src/lib.rs#L185-L188</a>):</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">PinnedDrop</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="c1">// `unsafe fn` or compiler magic cannot / should not be called directly,</span>
<span class="w">    </span><span class="c1">// except within an `Drop` impl:</span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="k">fn</span> <span class="nf">drop_pinned</span><span class="p">(</span><span class="bp">self</span>: <span class="nc">Pin</span><span class="o">&lt;&amp;'</span><span class="nb">_</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="bp">Self</span><span class="o">&gt;</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="cm">/* unsafe */</span><span class="w"> </span><span class="c1">// &lt;- see below</span>
<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="w"> </span>: <span class="o">?</span><span class="nb">Sized</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">PinnedDrop</span><span class="o">&gt;</span><span class="w"> </span><span class="nb">Drop</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">drop</span><span class="p">(</span><span class="bp">self</span>: <span class="kp">&amp;</span><span class="o">'</span><span class="nb">_</span> <span class="nc">mut</span><span class="w"> </span><span class="bp">Self</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">PinnedDrop</span>::<span class="n">drop_pinned</span><span class="p">(</span><span class="n">Pin</span>::<span class="n">new_unchecked</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>I suspect that writing this in <code>core</code> <em>as is</em> will probably cause coherence problems, so that's where I'd expect the compiler magic to kick in and manage to make this case work as expected.</p>
<hr>
<p>An extension to that would be, if that were possible within an edition boundary (I suspect it technically isn't, although it <em>could</em>), to then make <code>impl Drop</code> require <code>unsafe</code> unless we have <code>Self : Unpin</code>.</p>
<ul>
<li>That way, for the vast majority of types out there which are already <code>Unpin</code>, we still have <code>impl Drop</code> work as expected.</li>
<li>For types for which <code>Self : Unpin</code> does not generically hold (types that "are not" / "may not be" <code>Unpin</code>), then the compiler will error about the missing <code>unsafe</code>, suggesting the non-<code>unsafe</code> <code>PinnedDrop</code> trait be implemented instead.</li>
<li>Callers can still use <code>unsafe impl Drop</code> if they know what they are doing? (<em>e.g.</em>, they somehow know that all instances of <code>Self</code> will never be exposed to arbitrary code behind a <code>Pin</code>ning pointer) To be fair, I find this very much equivalent to not offering this option altogether, and requiring thats users use <code>Pin::get_unchecked_mut()</code> within a <code>PinnedDrop</code> implementation (way more explicit / readable way of using <code>unsafe</code>).</li>
</ul>



<a name="233103691"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233103691" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233103691">(Apr 04 2021 at 18:45)</a>:</h4>
<p>or just include an "optional" method</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="nb">Drop</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="cm">/* unsafe? */</span><span class="w"> </span><span class="k">fn</span> <span class="nf">drop</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">);</span><span class="w"></span>
<span class="w">  </span><span class="k">fn</span> <span class="nf">pin_drop</span><span class="p">(</span><span class="bp">self</span>: <span class="nc">Pin</span><span class="o">&lt;&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">Self</span><span class="o">&gt;</span><span class="p">);</span><span class="w"> </span><span class="cm">/* If type is Unpin, this uses normal drop if it is defined */</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="233103979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233103979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233103979">(Apr 04 2021 at 18:51)</a>:</h4>
<p>crazy idea: implement <code>DerefMut&lt;Target=T&gt; for Pin&lt;&amp;mut T&gt; where T: Unpin</code><br>
then drop signature will still be changed to <code>fn drop(self: Pin&lt;&amp;mut Self&gt;)</code>, but <code>self.field</code> will normally work</p>



<a name="233104269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233104269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233104269">(Apr 04 2021 at 18:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="328907">Soveu</span> <a href="#narrow/stream/268952-edition-2021/topic/Drop.20with.20pin.3F/near/233103979">said</a>:</p>
<blockquote>
<p>crazy idea: implement <code>DerefMut&lt;Target=T&gt; for Pin&lt;&amp;mut T&gt; where T: Unpin</code></p>
</blockquote>
<p>we already have that: <a href="https://doc.rust-lang.org/stable/std/pin/struct.Pin.html#impl-DerefMut">https://doc.rust-lang.org/stable/std/pin/struct.Pin.html#impl-DerefMut</a></p>



<a name="233105605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233105605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233105605">(Apr 04 2021 at 19:22)</a>:</h4>
<p>Then, what is the major issue with just changing the <code>fn drop</code> signature?<br>
In <code>Unpin</code> case (so in most of them)  it requires _just_ changing the receiver type</p>



<a name="233113693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233113693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233113693">(Apr 04 2021 at 21:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="328907">Soveu</span> <a href="#narrow/stream/268952-edition-2021/topic/Drop.20with.20pin.3F/near/233103691">said</a>:</p>
<blockquote>
<p>or just include an "optional" method</p>
<p><div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="nb">Drop</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="cm">/* unsafe? */</span><span class="w"> </span><span class="k">fn</span> <span class="nf">drop</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">);</span><span class="w"></span>
<span class="w">  </span><span class="k">fn</span> <span class="nf">pin_drop</span><span class="p">(</span><span class="bp">self</span>: <span class="nc">Pin</span><span class="o">&lt;&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">Self</span><span class="o">&gt;</span><span class="p">);</span><span class="w"> </span><span class="cm">/* If type is Unpin, this uses normal drop if it is defined */</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div><br>
</p>
</blockquote>
<p>This is what I was proposing above.</p>



<a name="233113782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233113782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233113782">(Apr 04 2021 at 21:21)</a>:</h4>
<p>But also, that raises an interesting notion.</p>



<a name="233113885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233113885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233113885">(Apr 04 2021 at 21:22)</a>:</h4>
<p>We could special-case <code>Drop::drop</code> in the compiler, such that if and <em>only</em> if your type implement <code>Unpin</code>, you're <em>allowed</em> (but not required) to write the signature as <code>fn drop(&amp;mut self)</code>, in which case the compiler will dereference the Pin for you. If your type doesn't implement <code>Unpin</code>, you start getting a compilation error in the edition, telling you very specifically that you need to write <code>fn drop(Pin&lt;&amp;mut self&gt;)</code> instead, and pointing to some hints about how to do that safely.</p>



<a name="233113902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233113902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233113902">(Apr 04 2021 at 21:22)</a>:</h4>
<p>Given how <em>many</em> drop impls exist, and how <em>few</em> of them need to worry about <code>Pin</code>, I think that would be worth doing to improve compatibility.</p>



<a name="233113928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233113928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233113928">(Apr 04 2021 at 21:23)</a>:</h4>
<p>That's roughly equivalent to the notion of <code>pin_drop</code>; either way we'd need some compiler special-casing.</p>



<a name="233281454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233281454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233281454">(Apr 06 2021 at 08:08)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/268952-edition-2021/topic/Drop.20with.20pin.3F/near/233113885">said</a>:</p>
<blockquote>
<p>We could special-case <code>Drop::drop</code> in the compiler, such that if and <em>only</em> if your type implement <code>Unpin</code>, you're <em>allowed</em> (but not required) to write the signature as <code>fn drop(&amp;mut self)</code>, in which case the compiler will dereference the Pin for you. If your type doesn't implement <code>Unpin</code>, you start getting a compilation error in the edition, telling you very specifically that you need to write <code>fn drop(Pin&lt;&amp;mut self&gt;)</code> instead, and pointing to some hints about how to do that safely.</p>
</blockquote>
<p>But what about types generic over some T, where T can be both pinned or <code>Unpin</code>ned?</p>



<a name="233373220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233373220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233373220">(Apr 06 2021 at 19:16)</a>:</h4>
<p><span class="user-mention" data-user-id="328907">@Soveu</span> Fair point.</p>



<a name="233479866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233479866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233479866">(Apr 07 2021 at 12:44)</a>:</h4>
<p>For now, we could allow both <code>&amp;mut self</code> and <code>Pin&lt;&amp;mut Self&gt;</code>, deprecating the first one</p>



<a name="233480230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/233480230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#233480230">(Apr 07 2021 at 12:47)</a>:</h4>
<p>So meanwhile we are talking about how to break the smallest subset of <a href="http://crates.io">crates.io</a>, the problem at least starts to fix itself :D</p>



<a name="234019569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234019569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234019569">(Apr 11 2021 at 06:09)</a>:</h4>
<p>Deprecating <code>fn drop(&amp;mut self)</code> is a... massive change that would cause a ton of churn.</p>



<a name="234290603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234290603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234290603">(Apr 13 2021 at 08:53)</a>:</h4>
<p>Do we have other option? Deprecation doesn't break code, it just generates a warning</p>



<a name="234367930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234367930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234367930">(Apr 13 2021 at 17:27)</a>:</h4>
<p>Honestly, I'm less concerned about the churn, and more concerned about the side effect of forcing the larger set of people who care about Drop to have to know about Pin.</p>



<a name="234368031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234368031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234368031">(Apr 13 2021 at 17:27)</a>:</h4>
<p>I would love to make it so that only people who need to deal with Pin already have to deal with it here, if that's possible.</p>



<a name="234368505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234368505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234368505">(Apr 13 2021 at 17:30)</a>:</h4>
<p><span class="user-mention silent" data-user-id="328907">Soveu</span> <a href="#narrow/stream/268952-edition-2021/topic/Drop.20with.20pin.3F/near/234290603">said</a>:</p>
<blockquote>
<p>Do we have other option? Deprecation doesn't break code, it just generates a warning</p>
</blockquote>
<p>Rust has a strong culture of wanting zero-warning builds, so that would still effect a lot churn</p>



<a name="234454481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234454481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234454481">(Apr 14 2021 at 07:37)</a>:</h4>
<blockquote>
<p>The side effect of forcing the larger set of people who care about Drop to have to know about Pin.</p>
</blockquote>
<p>what about something like: </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">DropGuard</span><span class="o">&lt;'</span><span class="na">a</span><span class="p">,</span><span class="w"> </span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">Pin</span><span class="o">&lt;&amp;'</span><span class="na">a</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">T</span><span class="o">&gt;</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>and <br>
<code>fn drop(self: DropGuard&lt;'_, Self&gt;) {...}</code></p>



<a name="234549512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234549512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234549512">(Apr 14 2021 at 18:22)</a>:</h4>
<p>We discussed this briefly in today's @T-lang design meeting. We agreed that this isn't going to be able to make the 2021 edition; it's just too last-minute and there's no concrete design proposal we're prepared to accept, so getting such a change through design, implementation, and stabilization would be too much.</p>



<a name="234549562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234549562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234549562">(Apr 14 2021 at 18:22)</a>:</h4>
<p>That said, we'd still like to see this worked on, just not tied to this edition.</p>



<a name="234549618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234549618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234549618">(Apr 14 2021 at 18:23)</a>:</h4>
<p>And we discovered that some people aren't seeing this discussion at all, because it's been in the edition 2021 stream.</p>



<a name="234549669"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234549669" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234549669">(Apr 14 2021 at 18:23)</a>:</h4>
<p>With that in mind, any objections to moving this thread elsewhere, either to the lang or libs stream?</p>



<a name="234549779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234549779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234549779">(Apr 14 2021 at 18:24)</a>:</h4>
<p>I think it may be worth clarifying that "still like to see this worked on" --- this is not meant, I think, to imply that there is consensus within the lang team on necessarily doing something here, just that there is interest in potentially seeing a proposal, correct?</p>



<a name="234549823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234549823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234549823">(Apr 14 2021 at 18:24)</a>:</h4>
<p>(I am happy to move the thread once we decide where. I lean towards lang, myself, but no strong opinion).</p>



<a name="234550237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234550237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234550237">(Apr 14 2021 at 18:27)</a>:</h4>
<p>I'm not suggesting that there was a consensus to do something; I'm suggesting that there was a consensus to continue discussing this and figure out if we should do something.</p>



<a name="234550381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234550381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234550381">(Apr 14 2021 at 18:28)</a>:</h4>
<p>I'd lean towards lang as well, since Drop is heavily language-integrated, and since some potential proposals for handling this would require language changes.</p>



<a name="234550854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234550854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234550854">(Apr 14 2021 at 18:31)</a>:</h4>
<p>Ok, well, I'll take that as brief consensus. Moving is pretty cheap. I'll do that :)</p>



<a name="234550881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234550881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Notification Bot <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234550881">(Apr 14 2021 at 18:31)</a>:</h4>
<p>This topic was moved here from <a class="stream-topic" data-stream-id="268952" href="/#narrow/stream/268952-edition-2021/topic/Drop.20with.20pin.3F">#edition 2021 &gt; Drop with pin?</a> by <span class="user-mention silent" data-user-id="116122">simulacrum</span></p>



<a name="234883656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234883656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234883656">(Apr 16 2021 at 16:28)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/213817-t-lang/topic/Drop.20with.20pin.3F/near/234368505">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="328907">Soveu</span> <a href="#narrow/stream/268952-edition-2021/topic/Drop.20with.20pin.3F/near/234290603">said</a>:</p>
<blockquote>
<p>Do we have other option? Deprecation doesn't break code, it just generates a warning</p>
</blockquote>
<p>Rust has a strong culture of wanting zero-warning builds, so that would still effect a lot churn</p>
</blockquote>
<p>That was kinda the idea - "force" people to fix their code by themselves :D</p>
<p>On the other hand, <em>just</em> accepting both <code>fn drop(&amp;mut self)</code> and <code>fn drop(self: Pin&lt;&amp;mut Self&gt;)</code>might be a decent idea for now - it doesn't break code and allows to use Pin for those who want it</p>



<a name="234885831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234885831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234885831">(Apr 16 2021 at 16:43)</a>:</h4>
<p><span class="user-mention" data-user-id="328907">@Soveu</span> I'd actually be happy to push people towards Pin if their types require it. I just don't want to make people whose types don't need to worry about Pin deal with Pin.</p>



<a name="234885885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234885885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234885885">(Apr 16 2021 at 16:43)</a>:</h4>
<p>So, it's fine if people who use Pin but have <code>drop</code> take just <code>&amp;mut self</code> get a warning, I just don't want <em>every</em> user of Drop to get a warning.</p>



<a name="234902363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234902363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234902363">(Apr 16 2021 at 18:42)</a>:</h4>
<p>how about changing <code>Drop</code> to require <code>Pin&lt;&amp;mut Self&gt;</code> if <code>Self: !Unpin</code> otherwise allow either <code>&amp;mut self</code> or <code>Pin&lt;&amp;mut self&gt;</code> on a new edition? <code>Drop</code> is already basically compiler magic since it doesn't act at all like a normal trait -- you can't call it directly and it doesn't really work in bounds (if I were redesigning Rust, I'd probably have it not be a trait)</p>



<a name="234902449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234902449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Quy Nguyen <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234902449">(Apr 16 2021 at 18:43)</a>:</h4>
<p>That would play havoc with generics that may or may not be <code>Unpin</code>.</p>



<a name="234902590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234902590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234902590">(Apr 16 2021 at 18:44)</a>:</h4>
<p>not really, just use the <code>Pin&lt;&amp;mut Self&gt;</code> version -- it works in both cases.</p>



<a name="234902865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234902865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234902865">(Apr 16 2021 at 18:46)</a>:</h4>
<p>That was one of the original ideas</p>



<a name="234902915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234902915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234902915">(Apr 16 2021 at 18:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="328907">Soveu</span> <a href="#narrow/stream/213817-t-lang/topic/Drop.20with.20pin.3F/near/233281454">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/268952-edition-2021/topic/Drop.20with.20pin.3F/near/233113885">said</a>:</p>
<blockquote>
<p>We could special-case <code>Drop::drop</code> in the compiler, such that if and <em>only</em> if your type implement <code>Unpin</code>, you're <em>allowed</em> (but not required) to write the signature as <code>fn drop(&amp;mut self)</code>, in which case the compiler will dereference the Pin for you. If your type doesn't implement <code>Unpin</code>, you start getting a compilation error in the edition, telling you very specifically that you need to write <code>fn drop(Pin&lt;&amp;mut self&gt;)</code> instead, and pointing to some hints about how to do that safely.</p>
</blockquote>
<p>But what about types generic over some T, where T can be both pinned or <code>Unpin</code>ned?</p>
</blockquote>



<a name="234903098"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234903098" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234903098">(Apr 16 2021 at 18:48)</a>:</h4>
<p><span class="user-mention silent" data-user-id="328907">Soveu</span> <a href="#narrow/stream/213817-t-lang/topic/Drop.20with.20pin.3F/near/234902865">said</a>:</p>
<blockquote>
<p>That was one of the original ideas</p>
</blockquote>
<p>guess that's what I get for not reading the whole history... :)</p>



<a name="234903149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234903149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234903149">(Apr 16 2021 at 18:48)</a>:</h4>
<p><span class="user-mention" data-user-id="328907">@Soveu</span> Hmmm. Since <code>Unpin</code> is an auto-trait, if you have a generic <code>T</code> that you don't know to be <code>Unpin</code>, that means you've declared it as <code>?Unpin</code>, right?</p>



<a name="234903228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234903228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234903228">(Apr 16 2021 at 18:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="229517">Jacob Lifshay</span> <a href="#narrow/stream/213817-t-lang/topic/Drop.20with.20pin.3F/near/234903098">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="328907">Soveu</span> <a href="#narrow/stream/213817-t-lang/topic/Drop.20with.20pin.3F/near/234902865">said</a>:</p>
<blockquote>
<p>That was one of the original ideas</p>
</blockquote>
<p>guess that's what I get for not reading the whole history... :)</p>
</blockquote>
<p>originally this topic was on <a class="stream" data-stream-id="268952" href="/#narrow/stream/268952-edition-2021">#edition 2021</a></p>



<a name="234903340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234903340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234903340">(Apr 16 2021 at 18:50)</a>:</h4>
<p>If that's the case, then I think it'd be perfectly fine to require using <code>Pin&lt;&amp;mut self&gt;</code> in that case, because you've mentioned <code>?Unpin</code> so it's OK to make you deal with pinning.</p>



<a name="234903403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234903403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234903403">(Apr 16 2021 at 18:50)</a>:</h4>
<p>Whereas if you write <code>impl&lt;T&gt; Drop for Foo&lt;T&gt;</code>, without mentioning pin/unpin, you get something that's <code>Unpin</code>, so it's OK to let you use <code>&amp;mut self</code>.</p>



<a name="234903888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234903888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234903888">(Apr 16 2021 at 18:54)</a>:</h4>
<p>It seems like that'd be a relatively reasonable and understandable heuristic for people to deal with.</p>



<a name="234904255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234904255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234904255">(Apr 16 2021 at 18:58)</a>:</h4>
<p>So <code>!Unpin</code> will go under <code>?Unpin</code> ?</p>



<a name="234904327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234904327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234904327">(Apr 16 2021 at 18:58)</a>:</h4>
<p>Right, either way you've mentioned pinning so you get to deal with pinning.</p>



<a name="234904401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234904401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234904401">(Apr 16 2021 at 18:58)</a>:</h4>
<p>If you can statically determine that the type is <code>Unpin</code> then you can use <code>&amp;mut self</code>, if not then you have to deal with <code>Pin&lt;&amp;mut self&gt;</code>.</p>



<a name="234904450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234904450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234904450">(Apr 16 2021 at 18:59)</a>:</h4>
<p>Pondering: since <code>Drop</code> is already a weird magic trait that you can't even call and <em>shouldn't</em> ever mention in bounds, we could start calling a different <code>PinDrop</code> in certain situations, right?</p>



<a name="234904624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234904624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234904624">(Apr 16 2021 at 19:00)</a>:</h4>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span> That would certainly make this change fit into the language better and be less magical. The only "downside" would be that you can't mention <code>Drop</code> bounds without accounting for <code>PinDrop</code>.</p>



<a name="234904736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234904736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234904736">(Apr 16 2021 at 19:01)</a>:</h4>
<p>Now the <code>?Unpin</code> solution that Josh proposed is my new favorite</p>



<a name="234904760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234904760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Quy Nguyen <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234904760">(Apr 16 2021 at 19:01)</a>:</h4>
<p>You could have compiler generated impls so you can still make sure a drop impl isn't provided. Or really I think blanket impls would work.</p>



<a name="234904970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234904970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234904970">(Apr 16 2021 at 19:02)</a>:</h4>
<p>Prior art: C# has both <code>IDisposable</code> and <a href="https://docs.microsoft.com/en-us/dotnet/api/system.iasyncdisposable?view=net-5.0"><code>IAsyncDisposable</code></a>, which is one of the things that had me thinking in that way.  <code>using var</code> will call the former, and <code>await using var</code> will call the latter.</p>
<p>(AsyncDrop isn't directly related to PinDrop, but whatever happens here might start to set precedent for the other.)</p>



<a name="234905041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234905041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234905041">(Apr 16 2021 at 19:03)</a>:</h4>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span> If we had both <code>Drop</code> and <code>PinDrop</code> (I can already see the puns coming), how would we expect people to drop things? Would <code>drop(x)</code> move to having a <code>PinDrop</code> bound, and we'd have a blanket impl from <code>Drop</code> to <code>PinDrop</code>?</p>



<a name="234905081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234905081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234905081">(Apr 16 2021 at 19:03)</a>:</h4>
<p>(I mean, technically <code>drop</code> doesn't actually express that bound...)</p>



<a name="234905345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234905345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234905345">(Apr 16 2021 at 19:05)</a>:</h4>
<p>Well <code>drop(x)</code> moves <code>x</code>, so doing it on a pinned value would be bad.</p>



<a name="234905893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234905893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234905893">(Apr 16 2021 at 19:10)</a>:</h4>
<p>imho <code>mem::drop</code> should always just be <code>pub fn drop&lt;T&gt;(_: T) {}</code></p>



<a name="234906454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234906454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234906454">(Apr 16 2021 at 19:14)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> so, you want <code>Unpin</code> to become like <code>Sized</code>?<br>
That would mean some types would start to reject pinned types, because of the implicit <code>Unpin</code> bound</p>



<a name="234906524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234906524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234906524">(Apr 16 2021 at 19:15)</a>:</h4>
<p><span class="user-mention" data-user-id="328907">@Soveu</span> I was under the impression it already is.</p>



<a name="234906549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234906549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234906549">(Apr 16 2021 at 19:15)</a>:</h4>
<p>It's an auto trait that's implemented by default.</p>



<a name="234906700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234906700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234906700">(Apr 16 2021 at 19:16)</a>:</h4>
<p>I wasn’t aware that the <code>?Trait</code> supported anything today besides <code>?Sized</code></p>



<a name="234906712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234906712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234906712">(Apr 16 2021 at 19:16)</a>:</h4>
<p>but I’d be happy to be proven wrong</p>



<a name="234906726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234906726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234906726">(Apr 16 2021 at 19:16)</a>:</h4>
<p>/me goes to look</p>



<a name="234906985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234906985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234906985">(Apr 16 2021 at 19:19)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Pinned</span><span class="p">(</span><span class="n">PhantomPinned</span><span class="p">);</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Wrapper</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span><span class="p">);</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">f</span><span class="p">(</span><span class="n">_</span>: <span class="kp">&amp;</span><span class="nc">Wrapper</span><span class="o">&lt;</span><span class="p">[</span><span class="kt">u8</span><span class="p">]</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"> </span><span class="c1">// this doesn't compile</span>
<span class="k">fn</span> <span class="nf">g</span><span class="p">(</span><span class="n">_</span>: <span class="kp">&amp;</span><span class="nc">Wrapper</span><span class="o">&lt;</span><span class="n">Pinned</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"> </span><span class="c1">// this does</span>
</code></pre></div>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span></p>



<a name="234907155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234907155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234907155">(Apr 16 2021 at 19:20)</a>:</h4>
<p>/me is a little confused about <code>Unpin</code> being an auto trait, then...</p>



<a name="234907239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234907239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234907239">(Apr 16 2021 at 19:20)</a>:</h4>
<p>Send and Sync are also auto-traits, but you don't have to specify ?Send + ?Sync every time you write a struct</p>



<a name="234907275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234907275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234907275">(Apr 16 2021 at 19:21)</a>:</h4>
<p>Ah, fair point.</p>



<a name="234907314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234907314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234907314">(Apr 16 2021 at 19:21)</a>:</h4>
<p>That makes sense; a trait can be automatic but not assumed in all trait bounds the way <code>Sized</code> is.</p>



<a name="234907329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234907329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234907329">(Apr 16 2021 at 19:21)</a>:</h4>
<p>Alright. Then this idea doesn't work at all.</p>



<a name="234907441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234907441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234907441">(Apr 16 2021 at 19:22)</a>:</h4>
<p>(well, i think the idea could be tied to an edition change. But its too late for 2021.)</p>



<a name="234907459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234907459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234907459">(Apr 16 2021 at 19:22)</a>:</h4>
<p>Another one is to massively hack negative bounds to allow them with Drop</p>



<a name="234907608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234907608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234907608">(Apr 16 2021 at 19:24)</a>:</h4>
<p>That would still mean that you couldn't write a <code>Drop</code> impl using <code>&amp;mut self</code> if you accepted a generic <code>T</code>, which breaks the premise of "you only have to deal with <code>Pin&lt;&amp;mut self&gt;</code> if you already deal with pinning".</p>



<a name="234907650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234907650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234907650">(Apr 16 2021 at 19:24)</a>:</h4>
<p>yeah</p>



<a name="234907755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234907755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234907755">(Apr 16 2021 at 19:25)</a>:</h4>
<p>(I was thinking something along the lines of “for new editions, <code>impl&lt;T&gt; Drop for …</code> has an implicit <code>T: Unpin</code> bound, and you <em>have</em> to write <code>impl&lt;T: ?Unpin&gt; Drop for …</code> if you don’t want it.)</p>



<a name="234907904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234907904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234907904">(Apr 16 2021 at 19:26)</a>:</h4>
<p>problem with this is, you can forget to add the bound and then suddenly, without any warning you lose your drop impl</p>



<a name="234907959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234907959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234907959">(Apr 16 2021 at 19:27)</a>:</h4>
<p>hmm</p>



<a name="234907978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234907978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234907978">(Apr 16 2021 at 19:27)</a>:</h4>
<p>that seems like something the compiler could error on</p>



<a name="234908039"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234908039" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234908039">(Apr 16 2021 at 19:27)</a>:</h4>
<p>we already require <code>impl Drop for Struct</code> to have a pretty strong match with the <code>struct Struct</code> declaration itself</p>



<a name="234908057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234908057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234908057">(Apr 16 2021 at 19:28)</a>:</h4>
<p>in terms of forcing the bounds to be the same in both cases</p>



<a name="234908131"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234908131" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234908131">(Apr 16 2021 at 19:28)</a>:</h4>
<p>The “lose your drop impl” that you describe <span class="user-mention" data-user-id="328907">@Soveu</span> sounds like another instance of that?</p>



<a name="234908204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234908204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234908204">(Apr 16 2021 at 19:28)</a>:</h4>
<p>As I said, for now maybe it will be good enough to allow both <code>fn drop(&amp;mut self)</code> and <code>fn drop(self: Pin&lt;&amp;mut Self&gt;)</code>unconditionally<br>
It is kinda how Josh wants it, no one needs to mess with Pin if they don't need/want to</p>



<a name="234908458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234908458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234908458">(Apr 16 2021 at 19:30)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116083">pnkfelix</span> <a href="#narrow/stream/213817-t-lang/topic/Drop.20with.20pin.3F/near/234907978">said</a>:</p>
<blockquote>
<p>that seems like something the compiler could error on</p>
</blockquote>
<p>How would compiler know if this is intentional or not?</p>



<a name="234908509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234908509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234908509">(Apr 16 2021 at 19:31)</a>:</h4>
<p><code>impl&lt;T&gt;</code> is <code>impl&lt;T&gt;</code></p>



<a name="234908611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234908611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234908611">(Apr 16 2021 at 19:32)</a>:</h4>
<p><span class="user-mention" data-user-id="328907">@Soveu</span> We could even require that you use <code>Pin&lt;&amp;mut self&gt;</code> if we can statically tell that you aren't Unpin.</p>



<a name="234908648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234908648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234908648">(Apr 16 2021 at 19:32)</a>:</h4>
<p>I think that'd be useful; we just don't want to give such warnings to <em>every</em> Drop impl out there.</p>



<a name="234908686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234908686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234908686">(Apr 16 2021 at 19:32)</a>:</h4>
<p><span class="user-mention silent" data-user-id="328907">Soveu</span> <a href="#narrow/stream/213817-t-lang/topic/Drop.20with.20pin.3F/near/234908458">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="116083">pnkfelix</span> <a href="#narrow/stream/213817-t-lang/topic/Drop.20with.20pin.3F/near/234907978">said</a>:</p>
<blockquote>
<p>that seems like something the compiler could error on</p>
</blockquote>
<p>How would compiler know if this is intentional or not?</p>
</blockquote>
<p>the idea is to force the developer to be consistent. The bounds on the drop impl have to match the bounds on the struct declaration.</p>



<a name="234908724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234908724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234908724">(Apr 16 2021 at 19:33)</a>:</h4>
<p>so you <em>can’t</em> just forget to add the bound\</p>



<a name="234908959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234908959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234908959">(Apr 16 2021 at 19:34)</a>:</h4>
<p>(but I admit, this may mean that my <code>impl&lt;T&gt; Drop</code> has implicit <code>T: Unpin</code> bound has more ramifications than I thought. It probably means that the <em>struct definition</em> for anything that implements <code>Drop</code> <em>also</em> needs to use the same rule.)</p>



<a name="234908974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234908974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234908974">(Apr 16 2021 at 19:34)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span>  ok, so then you have to add <code>+ ?Unpin</code> to every Box and every other smart pointer<br>
That's a (very confusing) breaking change</p>



<a name="234909034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234909034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234909034">(Apr 16 2021 at 19:35)</a>:</h4>
<p>I think you can add it to just the struct defintions though, not to every impl...</p>



<a name="234909089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234909089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234909089">(Apr 16 2021 at 19:35)</a>:</h4>
<p>and yeah, it would have to be tied to an edition boundary</p>



<a name="234909232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234909232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234909232">(Apr 16 2021 at 19:37)</a>:</h4>
<p>I admit it probably  would be too confusing to pass the sniff test.</p>



<a name="234909413"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234909413" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234909413">(Apr 16 2021 at 19:38)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Drop.20with.20pin.3F/near/234908648">said</a>:</p>
<blockquote>
<p>I think that'd be useful; we just don't want to give such warnings to <em>every</em> Drop impl out there.</p>
</blockquote>
<p>I mean, if we don't want to give warnings, we don't need to<br>
We already have the guarantees under the hood, it's "just" a change in signature</p>



<a name="234910004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234910004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234910004">(Apr 16 2021 at 19:44)</a>:</h4>
<p>i thought the point was that <code>&amp;mut self</code> is <em>wrong</em> in some cases?</p>



<a name="234910052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234910052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234910052">(Apr 16 2021 at 19:44)</a>:</h4>
<p>(or at least, <em>can be</em> wrong, depending on what one does in the <code>fn drop(&amp;mut self) { … }</code> itself?)</p>



<a name="234911269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234911269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234911269">(Apr 16 2021 at 19:54)</a>:</h4>
<p>Depends on your definition of "wrong"<br>
Drop could give you a <code>*mut ()</code>-  it would not be <em>wrong</em>, just very annoying to use</p>



<a name="234911994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234911994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234911994">(Apr 16 2021 at 19:59)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116083">pnkfelix</span> <a href="#narrow/stream/213817-t-lang/topic/Drop.20with.20pin.3F/near/234910052">said</a>:</p>
<blockquote>
<p>(or at least, <em>can be</em> wrong, depending on what one does in the <code>fn drop(&amp;mut self) { … }</code> itself?)</p>
</blockquote>
<p><a href="https://doc.rust-lang.org/std/pin/index.html#drop-implementation">https://doc.rust-lang.org/std/pin/index.html#drop-implementation</a></p>



<a name="234973075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234973075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234973075">(Apr 17 2021 at 08:48)</a>:</h4>
<p>I'd agree it is <em>wrong</em> in the sense that it does no accurately reflect the true capabilities of this pointer</p>



<a name="234973304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234973304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234973304">(Apr 17 2021 at 08:53)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Drop.20with.20pin.3F/near/234885885">said</a>:</p>
<blockquote>
<p>So, it's fine if people who use Pin but have <code>drop</code> take just <code>&amp;mut self</code> get a warning, I just don't want <em>every</em> user of Drop to get a warning.</p>
</blockquote>
<p>The users of <code>Drop</code> that would have to now care about <code>Pin</code> are those that implement generic types that are not always <code>Unpin</code>. What would be the best way to find out how many of those there are?<br>
I checked some of the common standard-library types and they all seem to be unconditionally <code>Unpin</code>, usually through auto trait implementations (since all ptr types are unconditionally <code>Unpin</code>).</p>



<a name="234973402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Drop%20with%20pin%3F/near/234973402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Drop.20with.20pin.3F.html#234973402">(Apr 17 2021 at 08:55)</a>:</h4>
<p>There are to ways to fix such types: make the unconditionally <code>Unpin</code> (this is always sound if there is no unsafe Pin-related code in this type), or properly work with <code>Pin&lt;&amp;mut T&gt;</code> in <code>drop</code>. Not doing either of these is still sound but only if there is no unsafe Pin-related code in this type (i.e., only if the type author merely forgot to make this <code>Unpin</code> even though they could have).</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>